<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Community_model extends CI_Model {

	function fetch_community_data($name)
	{								
		
		$data =  $this->db
						->get_where('tb_mas_community',array('strName'=>$name))
						->first_row();
						
		return $data;
						
	}
	
	function fetch_content_types()
	{								
		
		$data =  $this->db
						->get_where('tb_mas_content_types')
						->result_array();
						
		return $data;
						
	}
	
	function fetch_content($type,$cid,$limit=12,$offset=0)
	{					
		
                    $this->db
						->limit($limit,$offset)
						->order_by('dteStart desc')
						->where(array('fk-tb_mas_content_types'=>$type,'fk-tb_mas_community'=>$cid));
                    
                    if($type!=5)
                        $this->db->where(array('enumEnabled'=>'enabled'));
                    
                $data = $this->db
                         ->get('tb_mas_content')
                         ->result_array();
						
		return $data;
	}
	
	
	function get_featured_video($type,$cid)
	{
		$data =  $this->db						
						->order_by('dteStart desc')
						->get_where('tb_mas_content',array('fk-tb_mas_content_types'=>$type,'fk-tb_mas_community'=>$cid,'enumEnabled'=>'enabled'))
						->first_row();
						
		return $data;
	}
	
	function fetch_single_content($id)
	{						
		$data =  $this->db												
						->get_where('tb_mas_content',array('intID'=>$id,'enumEnabled'=>'enabled'))
						->result_array();
						
		return current($data);
	}
	
	function fetch_featured_images($cid)
	{
		$data = array();
		$temp =  $this->db
						->order_by('dteDate','desc')						
						->where(array('fk-tb_mas_community'=>$cid))
						->get('tb_mas_featured_image')
						->result_array();						
		
		foreach($temp as $t)
		{
			$item = $this->fetch_single_content($t['fk-tb_mas_content']);
			$t['contentType'] = $item['fk-tb_mas_content_types'];
			$data[] =  $t;
		}
		
		return $data;
	
	}
	
	private function fetch_meta($data)
	{
		
				
	
	}

}